package com.ruoyi.ajax;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.HouseErrorMsg;
import com.ruoyi.HouseException;

public class AjaxTools {
	public static  void exAjax(String ajaxString,HttpServletResponse response)throws HouseException {
		AjaxTools.exAjax(ajaxString, response, "AJAX数据输出操作");
	}
	/**
	 * 输出AJAX数据到页面
	 * @param ajaxString
	 * @param response
	 * @param logid
	 * @throws HouseException
	 */
	public static  void exAjax(String ajaxString,HttpServletResponse response,String logid)throws HouseException{
		PrintWriter out = null;
		try{
			String message = ajaxString == null ? "" : ajaxString.replaceAll("[\n]", "<br>");
			
			String logmsg = message.length() > 50000 ? message.substring(0,50000) : message;
			response.setContentType("text/html;charset=utf-8");
	        response.setHeader("Cache-Control", "no-cache");
	        out=response.getWriter();
	        out.write(message);
	        out.flush();
		}catch(Exception e){
			throw new HouseException(HouseErrorMsg.ERR_DEFAULT, "AJAX通讯出错!"+e.getMessage());
		}
		finally{
			out.close();
		}
	}
	/**
	 * 通过Ajax输出数组数据到页面
	 * @param ajaxString
	 * @param response
	 * @param logid
	 * @throws HouseException
	 */
	public static  void arrAjax(String ajaxString,HttpServletResponse response,String logid)throws HouseException{
		PrintWriter out = null;
		try{
			String message = ajaxString == null ? "" : ajaxString.replaceAll("[\n]", "<br>");
			response.setContentType("text/html;charset=utf-8");
			response.setHeader("Cache-Control", "no-cache");
			out=response.getWriter();
			out.write(message);
			out.flush();
		}catch(Exception e){
			throw new HouseException(HouseErrorMsg.ERR_DEFAULT, "AJAX通讯出错!"+e.getMessage());
		}
		finally{
			out.close();
		}
	}
	
	/**
	 * 输出AJAX数据到页面
	 * @param ajaxString
	 * @param response
	 * @throws HouseException
	 */
	public static  void outputAjax(String ajaxString,HttpServletResponse response)throws HouseException{
		PrintWriter out = null;
		try{
			String message = ajaxString == null ? "" : ajaxString.replaceAll("[\n]", "<br>");
			
			String logmsg = message.length() > 50000 ? message.substring(0,50000) : message;
			response.setContentType("text/html;charset=utf-8");
	        response.setHeader("Cache-Control", "no-cache");
	        out=response.getWriter();
	        out.write(message);
	        out.flush();
		}catch(Exception e){
			throw new HouseException(HouseErrorMsg.ERR_DEFAULT, "AJAX通讯出错!"+e.getMessage());
		}
		finally{
			out.close();
		}
	}

	public static void main(String args[]){
	
	}
}


